﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufExtension.h"
#include "GnufPreviewSpaceInput.h"
#include "GnufPallet.h"
#include "GnufQtObjectPtr.h"
#include <QPointer>


/* @example
 * gnuf::GnufPreviewSpaceInput previewInput;
 * previewInput.PreviewWgtInfo.IsIsolated = false;
 * previewInput.UiDocument = m_pUiDoc;
 * m_previewSpace = NEW_AS_OWNER_PTR(gnuf::BnufPreviewSpacePallet, previewInput);
 * QHBoxLayout* layout = NEW_AS_QT_LAYOUT(QHBoxLayout, m_ui.widget_Preview);
 * layout->setContentsMargins(0, 0, 0, 0);
 * layout->addWidget(m_previewSpace->pallet()->qtWidget());
 * m_ui.widget_Preview->setLayout(layout);
 * m_previewSpace->SetPreviewSpcaeModifyActionCommand(ID_CMD_PREVIEW_EMPTY_MODIFY);
 * m_preViewModelView = m_previewSpace->GetModelView();
 *
 * IPreviewDataForModelView::RegisterPreviewExternalData(m_pUiDoc->GetDbDocument(), m_preViewModelView);
 * //设置过滤器
 * gcmp::OwnerPtr<IPreviewDefaultedVisibilityFilter>  opPreviewDefaultedFilter = IPreviewDefaultedVisibilityFilter::Create(NEW_AS_OWNER_PTR(PreviewVisibilityFilter, m_pUiDoc->GetDbDocument()));
 * m_preViewModelView->AddElementVisibilityFilter(TransferOwnership(opPreviewDefaultedFilter));
*/

namespace gnuf
{
    class QtPreviewSpacePallet;

    class GNUF_EXTENSION_EXPORT GnufPreviewSpacePallet
    {
    public:
        GnufPreviewSpacePallet(const GnufPreviewSpaceInput& input);
        virtual ~GnufPreviewSpacePallet() {} //允许继承

    public:
        void Show();
        bool Close();
        bool StartPreview(gcmp::OwnerPtr<gcmp::IElementVisibilityFilter> opVisibilityFilter);
        bool EndPreview();
        bool Refresh();
        bool ZoomAll();
        gcmp::IModelView* GetModelView();
        bool SetPreviewSpcaeModifyActionCommand(const std::wstring& commandName);
        int GetWindowWidth() const;
        void SetWindowWidth(int width);
        int GetWindowHeight() const;
        void SetWindowHeight(int height);
        gcmp::Vector2i GetWindowPosition() const;
        void SetWindowPosition(int x, int y);
        std::vector<const gcmp::IGraphicsElementShape*> GetVisibleGreps();
        void MarkNeedRebuild(bool needRebuild);

    public:
        Pallet* pallet() { return m_pallet.get(); }
        const Pallet* pallet() const { return m_pallet.get(); }

    protected:
        const GnufPreviewSpaceInput& param() const { return m_param; }

    private:
        void initialize(const GnufPreviewWgtInfo&);

    private:
        QPointer<QtPreviewSpacePallet> m_nativePallet;
        gcmp::OwnerPtr<Pallet> m_pallet;
        GnufPreviewSpaceInput m_param;

        friend class QtPreviewSpacePallet;
    };
}



